package com.qf.controller;

import com.qf.entity.Merchant;
import com.qf.service.MerchantService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

//商家控制器层
@RestController
@RequestMapping("/MerchantController")
public class MerchantController {

    @Autowired
    private MerchantService merchantService;
    /**
     * 查询所有的商家
     * @return
     */
    @RequestMapping("/selAllMerchant")
    public List<Merchant> selAllMerchant(){
        return merchantService.selAllMerchant();
    }


    /**
     * 根据商家分类的id去查询商家信息
     * 数据库中  商家里面有一个外键 是商家分类的id
     * @param mc_id
     * @return
     */
    @GetMapping("/selMerchantByMerchant_categoryId/{mc_id}")
    public List<Merchant> selMerchantByMerchant_categoryId(@PathVariable("mc_id") int mc_id){
       return merchantService.selMerchantByMerchant_categoryId(mc_id);
    }

    /**
     * 根据远近最快  1,2,3,4  来查询商家
     * @param vip
     * @return
     */
    @RequestMapping("/selMerchantByVip/{vip}")
    public List<Merchant> selMerchantByVip(@PathVariable("vip") String vip){
        List<Merchant> merchantList = merchantService.selMerchantByVip(vip);
        for (Merchant merchant: merchantList) {
            System.out.println("AAAAAAAAAAAAAAA======================="+merchant);
        }
        return merchantList;
    }

    /**
     * 根据商家名称迷糊搜索
     * @param m_name
     * @return
     */
    @RequestMapping("/selAllMerchantByName/{m_name}")
    public List<Merchant> selAllMerchantByName(@PathVariable("m_name") String m_name){
        List<Merchant> merchantsList = merchantService.selAllMerchantByName(m_name);
        return merchantsList;
    }
}
